<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>仿京东显示密码</title>
    <style>
        .box{
            position: relative;
            width: 400px;
            border-bottom: 1px solid #ccc;
            margin: 100px auto;
        }
        .box input{
            width: 370px;
            height: 30px;
            border: 0;
            /* 边框不显示 */
            outline: none;
        }
        .box img {
            position: absolute;
            top: 5px;
            right: 5px;
            width: 24px;
        }
    </style>
</head>
<body>
    <div class="box">
        <label for="">
            <img src="img.png" id="eye">
        </label>
        <input type="password" id="pwd">
    </div>
    <span class="message">请输入6~16位密码</span>
    <script>
        var eye = document.getElementById('eye')
        var pwd = document.getElementById('pwd')
        var message = document.querySelector('.message')
        var flag = 0;
        eye.onclick = function() {
            if (flag == 0) {
                pwd.type=Text;
                eye.src='my.png';
                flag = 1;
            }
            else{
                pwd.type='password';
                eye.src='img.png';
                flag = 0;
            }
        }
        pwd.onblur = function(){
            if (this.value.length < 6 || this.value.length > 16) {
                message.innerHTML='你输入的位数不对要求6~16位'
                message.style.background = 'red'
            }
            else{
                message.innerHTML='你输入正确！'
                message.style.background = 'green'
            }
        }
    </script>
</body>
</html>